import Vue from 'vue'
import 'normalize.css/normalize.css' // A modern alternative to CSS resets
import ElementUI from 'element-ui'
import './styles/element-variables.scss'
import 'element-ui/lib/theme-chalk/index.css'
import '@/styles/index.scss' // global css
import App from './App'
import store from './store'
import router from './router'
import '@/icons' // icon
import '@/permission' // permission control
import { get, post } from '@/utils/myajax'
import axios from 'axios'
import Vue2OrgTree from 'vue2-org-tree'

Vue.use(Vue2OrgTree)
/* import VuePrism from 'vue-prism'
import 'prismjs/themes/prism.css'
Vue.use(VuePrism) */
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */
axios.defaults.baseURL = 'http://www.traning-ai.cn:8082'
// axios.defaults.baseURL = 'http://127.0.0.1:8082'
axios.defaults.timeout = 50000
Vue.prototype.axios = axios
Vue.prototype.extend = require('extend')
Vue.prototype.get = get
Vue.prototype.imgurl = 'http://www.traning-ai.cn:8080/'

Vue.prototype.redirect = function(module, params = {}) {
  this.$store.commit('user/SET_PARAMS', params)
  this.$router.push({
    name: module
  })
}

Vue.prototype.post = function(url, formName, callback = result => {}, params = {}) {
  if (formName) {
    this.$refs[formName].validate((valid) => {
      if (valid) {
        post(url, params, callback)
      }
    })
  } else {
    post(url, params, callback)
  }
}
Vue.prototype.del = function(url, callback, params, txt) {
  this.$confirm(txt, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    this.get(url, result => {
      this.$message({
        type: 'info',
        message: result.message
      })
      callback(result)
    }, params)
  }).catch(() => {
    this.$message({
      type: 'info',
      message: '已取消'
    })
  })
}

import { mockXHR } from '../mock'
if (process.env.NODE_ENV === 'production') {
  mockXHR()
}

// set ElementUI lang to EN
Vue.use(ElementUI)
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
